import logging
import time

from appium.webdriver.common.mobileby import MobileBy

from base.base_page import BasePage
from pages.personal_info_page import PersonalInfoPage


class SearchPage(BasePage):

    _search_input_locator = (MobileBy.XPATH, "//*[@text='搜索']")

    def search_member(self, name):
        logging.info("调用search_member方法")
        self.find_and_input(name, self._search_input_locator)
        time.sleep(3)
        return self.find_all(MobileBy.XPATH, f"//*[@text='联系人']/../following-sibling::*")

    def go_to_personal_info(self, name):
        logging.info("调用go_to_personal_info方法")
        self.find_and_click((MobileBy.XPATH, f"//*[@text='联系人']/../following-sibling::*//*[@text='{name}']"))
        return PersonalInfoPage(self.driver)